﻿using UnityEngine;
using System.Collections;

public class ResourceLoader : Loader
{
	ResourceRequest m_request = null;
	public ResourceLoader()
		: base(Loader.LoaderType.RESOURCE)
	{
		
	}

	public override void Load()
	{
		base.Load();

		if (m_async)
		{
			m_request = Resources.LoadAsync(m_path);
		}
		else
		{
			Object obj = Resources.Load(m_path);
			OnLoadCompleted(obj);
		}
	}

	public override void Update(float dt)
	{
		if (m_state == LoaderState.LOADING)
		{
			if (m_request == null)
			{
				OnLoadCompleted(null);
			}
			else if (m_request.isDone)
			{
				OnLoadCompleted(m_request.asset);
				m_request = null;
			}
			else
			{
				OnLoadProgress(m_request.progress);
			}
		}
	}
}